package vooga.behaviors;

import java.awt.geom.Rectangle2D;

import vooga.entities.Entity;

/**
 * Makes an Entity bounce off of a bound
 * @author congyiwu
 *
 */
public class BounceOnBoundsBehavior extends AbstractBehavior {
	protected Rectangle2D myBounds;

	public BounceOnBoundsBehavior(Rectangle2D bounds) {
		myBounds = bounds;
	}

	public void step(Entity target)
	{
		AbstractBehavior flip = null;
		// bounce off the left or right walls
		if((target.getLeft() <= myBounds.getMinX()) )
			{
			target.getVelocity().setXChange((Math.abs(target.getVelocity().getXChange())));
			//flip = new BounceRightBehavior();
			}
		else if(target.getRight() >= myBounds.getMaxX())
			{
			target.getVelocity().setXChange(-Math.abs(target.getVelocity().getXChange()));
			//flip = new BounceLeftBehavior();
			}
	
		// bounce off the top or bottom walls
		if ((target.getTop() <= myBounds.getMinY()))
			{
			target.getVelocity().setYChange(Math.abs(target.getVelocity().getYChange()));
			//flip = new BounceDownBehavior();
			}
		else if(target.getBottom() >= myBounds.getMaxY())
			{
			target.getVelocity().setYChange(-Math.abs(target.getVelocity().getYChange()));
			//flip = new BounceUpBehavior();
			}
		
		if(flip != null)
			{
			flip.step(target);
			}
	}
}
